package microcredit.gui.handler;

import java.awt.Component;
import java.util.ArrayList;
import java.util.List;

import javax.swing.SwingWorker;

import microcredit.gui.util.ReportWorker;
import microcredit.model.Report;
import microcredit.model.bo.BOReport;
import net.sf.jasperreports.engine.JasperPrint;

public class ReportHandler extends AbstractHandler<Report> {


	@Override
	public List<Report> load() throws Throwable {
		List<Report> reports = BOReport.create().getReports();
		List<Report> filteredReports = new ArrayList<Report>();
		for (Report report : reports) {
			if (report.isDisplay()) {
				filteredReports.add(report);
			}
		}
		return filteredReports;
	}
	
	@Override
	public Report open(Component component, final Report e) throws Throwable {
		SwingWorker<JasperPrint, Object> worker = new ReportWorker(e, null);
		worker.run();
		return null;
	}
	
}
